﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRMWeb.Utilities.Context;
using System.Data;
using System.Web.Services;
using CRMBiz;
namespace CRMWeb.UserControls
{
    public partial class ApplicationProfile : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            hdnUserName.Value = CMSContext.CurrentUser.MemberName;
            var repVal = "";
            var folderPath = "";
            /*If app_id is null*/
            if (Request.Params["app_id"] == null & Request.Params["contact_id"] != null)
            {

            }
            else
            {
                DataTable dt = GetFolderName(Convert.ToInt32(Request.Params["app_id"]));
                if (dt.Rows.Count != 0)
                {
                    repVal = dt.Rows[0]["Folder"].ToString();
                }

                /*If string contains 'file&' then*/
                if (repVal.Contains("file&"))
                {
                    var addVal = repVal.Replace('\\','/');
                    folderValue.HRef = addVal.Replace('&', ':');
                    txtapp_folder.Value = addVal.Replace('&', ':');
                    hdn_txtapp_folder.Value = addVal.Replace('&', ':');
                }

                /*If string contains '&/' for local drives*/
                else if (repVal.Contains("&/"))
                {
                    folderPath = "file:///" + repVal.Replace('\\', '/');
                    folderValue.HRef = folderPath.Replace('&', ':');
                    txtapp_folder.Value = folderPath.Replace('&', ':');
                    hdn_txtapp_folder.Value = folderPath.Replace('&', ':');
                }
                else
                {
                    /*If string contains network folder*/
                    folderPath = "file:///" + repVal.Replace('\\', '/');
                    folderValue.HRef = folderPath.Replace('&', ':');
                    txtapp_folder.Value = folderPath.Replace('&', ':');
                    hdn_txtapp_folder.Value = folderPath.Replace('&', ':');
                }




            }
        }

        //Get folder path to set the value on plugin:
        [WebMethod]
        public DataTable GetFolderName(Int64 appid)
        {
            return ClientProfileHandler.GetFolderName(appid);
        }

    }



}